package com.my.cd.memo;

import java.util.ArrayList;
import java.util.List;

/**
 * 另一个：进度或状态存储发起者。
 */
public class Originator2 {

    private List<String> state;

    public Originator2() {
        state = new ArrayList<>();
    }

    public Memento createMemento() {
        return new MementoB(state);
    }

    public void restoreMemento(Memento memento) {
        state = ((MementoB) memento).getState();
    }

    public void testState1() {
        state = new ArrayList<>();
        state.add("blood:320");
        state.add("progress:gate2 mid");
        state.add("enemy:15");

    }

    public void testState2() {
        state = new ArrayList<>();
        state.add("blood:230");
        state.add("progress:gate8 last");
        state.add("enemy:12");

    }

    public void showState() {
        System.out.println("now state:" + state.toString());
    }

    private class MementoB implements Memento {

        private List<String> state;

        private MementoB(List<String> state) {
            this.state = new ArrayList<>(state);
        }

        private List<String> getState() {
            return state;
        }

        private void setState(List<String> state) {
            this.state = state;
        }
    }
}
